package com.xyht.sca_s.student_manage_system.modules.dormitory.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryBedAddMyReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryBedAddReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryBedDeletedOwnershipReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryBedUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.service.SmsDormitoryBedService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 床号管理表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-08
 */
@RestController
@RequestMapping("/dormitory/dormitoryBed")
@SecretBody
public class SmsDormitoryBedController {

    @Resource
    private JwtTokenUtil jwtTokenUtil;
    @Resource
    private SmsDormitoryBedService smsDormitoryBedService;

    @ApiOperation("添加宿舍")
    @PostMapping("/add")
    public ResponseResult addDormitoryBed(HttpServletRequest request, @RequestBody SmsDormitoryBedAddReq addReq){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsDormitoryBedService.addDormitoryBed(userId,addReq);
    }


    @ApiOperation("查看宿舍床详情")
    @GetMapping("/id")
    public ResponseResult getDormitoryBedDetail(@RequestParam(value = "id") String id){
        return smsDormitoryBedService.getDormitoryBedDetail(id);
    }

    @ApiOperation("修改床位信息")
    @PostMapping("/updateBedInfo")
    public ResponseResult updateDormitoryBed(@RequestBody SmsDormitoryBedUpdateReq updateReq){
        return smsDormitoryBedService.updateDormitoryBed(updateReq);
    }

    @ApiOperation("查看床位列表")
    @GetMapping("/list")
    public ResponseResult getDormitoryBedList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                               @RequestParam(value = "dormitoryId") String dormitoryId,
                                               @RequestParam(value = "stuName", required = false) String stuName,
                                               @RequestParam(value = "stuCollege", required = false) String stuCollege,
                                               @RequestParam(value = "stuMajor", required = false) String stuMajor,
                                               @RequestParam(value = "stuGrade", required = false) String stuGrade,
                                               @RequestParam(value = "stuClass", required = false) String stuClass,
                                               @RequestParam(value = "bedNo", required = false) String bedNo,
                                               @RequestParam(value = "feeStandards", required = false) String feeStandards) {
        return smsDormitoryBedService.getDormitoryBedList(pageNum,pageSize,dormitoryId,stuName,stuCollege,stuMajor,stuGrade,stuClass,bedNo,feeStandards);
    }

    @ApiOperation("查看组织架构")
    @GetMapping("/org")
    public ResponseResult getOrg(@RequestParam(value = "type") Integer type,
                                  @RequestParam(value = "parentId",required = false) Integer parentId){
        return smsDormitoryBedService.getOrg(type,parentId);
    }

    @ApiOperation("清空指定寝室的归属")
    @PostMapping("/deletedDormitoryOwnership")
    public ResponseResult deletedDormitoryOwnership(@RequestBody SmsDormitoryBedDeletedOwnershipReq deletedOwnershipReq){
        return smsDormitoryBedService.deletedDormitoryOwnership(deletedOwnershipReq);
    }

    @ApiOperation("查看自己的寝室")
    @GetMapping("/getMyDormitoryBed")
    public ResponseResult getMyDormitoryBed(HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsDormitoryBedService.getMyDormitoryBed(userId);
    }

    @ApiOperation("选择寝室列表")
    @GetMapping("/chooseDormitoryList")
    public ResponseResult chooseDormitoryList(HttpServletRequest request,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsDormitoryBedService.chooseDormitoryList(pageNum,pageSize,userId);
    }

    @ApiOperation("添加自己的床位")
    @PostMapping("/addMyDormitoryBed")
    public ResponseResult addMyDormitoryBed(@RequestBody SmsDormitoryBedAddMyReq addMyReq,HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsDormitoryBedService.addMyDormitoryBed(addMyReq,userId);
    }

}

